﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestSolveWithLowTriangle.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.CrcsSparseMatrixTest.DoubleExtensions
{
    #region Usings

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="CrcsSparseMatrixExtensions.SolveWithLowTriangle"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.CrcsSparseMatrixExtensions")]
    public sealed class TestSolveWithLowTriangle
    {
        #region Methods

        #region public

        /// <summary>
        ///     Tests the method when parameters are valid.
        /// </summary>
        [Test]
        public void WhenParametersAreValid()
        {
            // Arrange:
            // Matrix:
            // 1 2 0  3
            // 0 3 0 12
            // 2 8 5 47
            // 6 0 0 25
            var matrix = new CrcsSparseMatrix<double>(
                lowTriangleRowsBegins: new[] { 0, 0, 0, 2, 3 },
                lowTriangleColumnsIndexes: new[] { 0, 1, 0 },
                highTriangleColumnsBegins: new[] { 0, 0, 1, 1, 4 },
                highTriangleRowsIndexes: new[] { 0, 0, 1, 2 },
                lowTriangleData: new double[] { 2, 8, 6 },
                diagonalData: new double[] { 1, 3, 5, 25 },
                highTriangleData: new double[] { 2, 3, 12, 47 });
            var rightHandPart = new DenseVector<double>(new double[] { 10, 100, 1820, 10060 });

            // Act
            matrix.SolveWithLowTriangle(rightHandPart);

            // Assert
            Assert.That(rightHandPart.Values, Is.EquivalentTo(new double[] { 10, 100, 1000, 10000 }));
        }

        #endregion

        #endregion
    }
}